package mytask.domain;

import java.util.MissingResourceException;
import java.util.ResourceBundle;

public final class TranslationManager {

	public static final String[] LOCALE_FILES = { "et", "en" }; //$NON-NLS-0$ //$NON-NLS-1$

	private String m_activeLocale = LOCALE_FILES[0];

	private ResourceBundle m_resourceBundle = ResourceBundle.getBundle(m_activeLocale);

	private static TranslationManager instance = new TranslationManager();

	private TranslationManager() {
	}

	public String getLocaleFile() {
		return m_activeLocale;
	}

	public void setLocaleFile(final String localeFile) {
		m_activeLocale = localeFile;
		m_resourceBundle = ResourceBundle.getBundle(m_activeLocale);
	}

	public ResourceBundle getResourceBundle() {
		return m_resourceBundle;
	}

	public static TranslationManager getInstance() {
		return instance;
	}

	public static String get(final String key) {
		try {
			return TranslationManager.getInstance().getResourceBundle().getString(key);
		} catch (final MissingResourceException e) {
			return '!' + key + '!';
		}
	}
}
